<?php


require 'conf.inc.php'; 

/*
function print_item ($i) {
  
  global $products;
  
  $item = '';
 
  $item = '<div class="ui-grid-solo" style="text-align:center">';
  $item .= '<div class="ui-block-a"> 
              <div class="ui-bar"><a data-parm="ciao" href="#two"><img src="' . $products['riviste'][$i]['image_src'] . '"/></a></div></div>';  
  $item .= '<div class="ui-block-a"> 
              <div class="ui-bar" style="height:15px; font-size: 11px">' . $products['riviste'][$i]['description'] . '</div></div>';
  // $item .= '<div class="ui-block-a">
              // <div class="ui-bar" style="height:10px; font-size: 12px; color: darkred">' . $products['riviste'][$i]['price_label'] . '</div></div>';
  $item .= '</div>'; 
  
  return $item;
  
}
*/
function print_gallery (array $categories, $min, $max, array $g, array $tag) {
   
    
    $j=0;

    global $products;
    
    
    
    // echo '<ul>';
    // while ( $j<6 ) 
      // {
        // if ($products['riviste'][$j]['price'] >= $min and $products['riviste'][$j]['price'] <= $max )
            // echo '<li style="border-left: none">' . print_item($j)  . '</li>';
        // $j++;
       // }
//          
    // echo '</ul>';     
	$stringHtml = "";
	foreach($products as $_category => $prodCat){
		if(in_array(strtolower($_category),$categories)){
			foreach($prodCat as $prod){		
				if(!in_array($prod['gender'],$g)) continue;
				if ($prod['price'] >= $min and $prod['price'] <= $max ){
					$stringHtml .= '<div class="block description">
										<a href="#">
											<img src="' . $prod['image_src'] . '" width="82%"/>
											<p class="prodShorDesc">' . $prod['short_description'] . '</p>
										</a>
										<div class="addGift" style="margin-right:2px">
											<a class="notselected" href="#" name="addProduct" id="products['.$_category.'][' . $prod['id'] . ']" >
												<span> Aggiungi </span>
											</a>
										</div>
									</div>';
									//<div class="block">  Pretty row 2 </div>';   <img src="/images/glyphish-icons-png/10-medical.png" alt="Add to GiftShake" />
				}
			}
		}else{
			foreach($prodCat as $prod){	
				if(!in_array(strtolower($prod['tag']),$tag)) continue;
				
				if ($prod['price'] >= $min and $prod['price'] <= $max ){
					$stringHtml .= '<div class="block description">
										<a href="#">
											<img src="' . $prod['image_src'] . '" width="82%"/>
											<p class="prodShorDesc">' . $prod['short_description'] . '</p>
										</a>
										<div class="addGift">
											<a href="#" name="addProduct" id="products['.$_category.'][' . $prod['id'] . ']" >
												<img src="/images/glyphish-icons-png/10-medical.png" alt="Add to GiftShake" />
											</a>
										</div>
									</div>';
									//<div class="block">  Pretty row 2 </div>';
				}					
			}
			
		}

	}
	echo $stringHtml;
 
	/*
     echo '<div class="block description">
      <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>           
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][0]['id'] . ']" >Add</a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][1]['image_src'] . '"/>
           <p>' . $products['riviste'][1]['description'] . '</p>           
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][1]['id'] . ']" >Add</a>    
           </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][2]['image_src'] . '"/>
           <p>' . $products['riviste'][2]['description'] . '</p>
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][2]['id'] . ']" >Add</a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][3]['image_src'] . '"/>
           <p>' . $products['riviste'][3]['description'] . '</p>
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][3]['id'] . ']" >Add</a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][4]['image_src'] . '"/>
           <p>' . $products['riviste'][4]['description'] . '</p>
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][4]['id'] . ']" >Add</a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][5]['image_src'] . '"/>
           <p>' . $products['riviste'][5]['description'] . '</p>           
           </a><a href="#" name="addProduct" id="products[riviste][' . $products['riviste'][5]['id'] . ']" >Add</a>
    </div>
    <div class="block">  Pretty row 2 </div>
    ';
   */
 
   
  }


  //echo 'parametro via get:  ' . $_GET['param'];

  //$budget_min = 0;//$_POST['budget_min'];
  //$budget_max = 100;//$_POST['budget_max'];
  
	
  
	$tipo = $_GET['tipo']; // male/female/couple
	$budget = $_GET['budget'];
	$profilo = $_GET['profilo']; //array
	//print_r($profilo);
	$categorie = array();
	foreach($profilo as $_prof){
		switch(strtolower($_prof)){
			case "avventuruoso":
				$categorie[] = "giornate-avventura";
				break;
			case "lettore":
				$categorie[]="riviste";
				break;
			case "sportivo":
				$categorie[]="accessori-sport";
				break;				
			case "tecnologico":
				$categorie[]="elettronica";
				break;		
			case "vanitoso":
				$categorie[]="gioielli";
				break;			
			case "elegante":
				$categorie[]="peccati-di-gola";
				break;	
		}
	}
	
	if(count($categorie)==0)
		$categorie[]="peccati-di-gola";
		
	switch(strtolower($tipo)){
		case "male":
			$gender=array("M/F","M");
			break;
		case "female":
			$gender=array("M/F","F");
			break;
		case "couple":
			$gender=array("M/F");
			break;
	}
    
	//print_r($categorie);

    // il budget è fisso. Sono mostrati i prodotti che hanno quel prezzo.

	$budget_min = $budget-20;
  	$budget_max = $budget;


  	print_gallery($categorie, $budget_min, $budget_max, $gender,$profilo);




?>